package com.presentacion.houseon;

import java.util.ArrayList;

import com.model.houseon.DispositivoBean;



import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ItemDispositivoAdapter extends BaseAdapter {
	protected Activity activity;
	protected ArrayList<DispositivoBean> items;
	  
	public ItemDispositivoAdapter(Activity activity, ArrayList<DispositivoBean> items) {
	    this.activity = activity;
	    this.items = items;
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return items.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return items.get(position);
	}

	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return items.get(arg0).idDispositivo;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View vi=convertView;
        
	    if(convertView == null) {
	      LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	      vi = inflater.inflate(R.layout.item_dispositivo, null);
	    }
	             
	    DispositivoBean item = items.get(position);
	         
	    ImageView image = (ImageView) vi.findViewById(R.id.imgEscenario);
	    int imageResource = activity.getResources().getIdentifier(item.rutaImagen, null, activity.getPackageName());
	    image.setImageDrawable(activity.getResources().getDrawable(imageResource));
	         
	    TextView nombre = (TextView) vi.findViewById(R.id.nombre);
	    nombre.setText(item.nombre);

	    return vi;
	}

}
